Skip to content

NH-4003 - porting ISessionCreationOptions #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2017

Conversation

fredericDelaporte
Copy link
Member

NH-4003 - Refactor session constructor

I consider this as a prerequisite for porting the current transaction handling from Hibernate. This handling especially relies on the ISharedSessionBuilder, introduced by this PR.

I have dropped the obsolete parameter InterceptorsBeforeTransactionCompletionIgnoreExceptions in the process.

The GetChildSession introduced in 5.0 by the removal of entity mode switching is removed in favor of Hibernate ISession.WithSessionOptions() which yield a builder of session, allowing to build new sessions taking a part of their stuff (like the connection manager currently) from the original session. These new sessions are not closed or flushed from the original session.

I have reintroduced as obsolete the old ISession.GetSession(), for hinting at using ISession.WithSessionOptions().

All that by the way obsoletes NH-3985 (already resolved, #600, about disposed child session being returned) and NH-3986 (Enable multiple child sessions per root session: the new semantic allows this, though there are no more actually children, the "parent" has no knowledge of them currently).

Some stuff has moved around, Hibernate having put many more things in the AbstractSessionImpl.

Never,

[System.Xml.Serialization.XmlEnumAttribute("manual")]
Manual,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually adjusted. The Never mode has been renamed Manual on Hibernate side, which looks more accurate to me. Still supporting Never for backward compatibility.

@@ -81,6 +81,8 @@ public Settings()

public bool IsIdentifierRollbackEnabled { get; internal set; }

// Since v5
[Obsolete("Please use DefaultFlushMode instead.")]
public bool IsFlushBeforeCompletionEnabled { get; internal set; }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was already having no usages. Now maybe will it have some once Hibernate transaction management will be ported.

/// <summary>
/// The singleton reference.
/// </summary>
public static readonly EmptyInterceptor Instance = new EmptyInterceptor();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realigning on Hibernate pattern. Creating it at each usage was not making much sens.

/// <summary>
/// Represents a consolidation of all session creation options into a builder style delegate.
/// </summary>
public interface ISessionBuilder<T> where T : ISessionBuilder<T>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Java session builder interface uses covariant return type: its methods are fluent, and return the most derived interface (ISharedSessionBuilder by example). It is a bit messy to achieve in .Net.

/// </summary>
/// <param name="conn">A connection provided by the application</param>
/// <returns>The session builder.</returns>
ISessionBuilder WithOptions();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The factory has now only one non obsolete method for opening stateful session, and it returns a session builder. A session builder can be used for opening as many session as we wish.

ISession _childSession;

[NonSerialized]
private readonly bool flushBeforeCompletionEnabled;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fields removed.

private readonly ConnectionReleaseMode connectionReleaseMode;
[NonSerialized]
private readonly bool _transactionCoordinatorShared;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NH addition, I expect this to be no more needed once transaction handling will be ported.

@@ -140,15 +126,19 @@ void ISerializable.GetObjectData(SerializationInfo info, StreamingContext contex
{
throw new InvalidOperationException("Cannot serialize a Session while connected");
}
if (_transactionCoordinatorShared)
{
throw new InvalidOperationException("Cannot serialize a Session sharing its transaction coordinator");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After deserialization, the shared thing (currently connection manager) would be no more shared.

return interceptor.EntityName;
// NH: support of field-Interceptor-proxy
IFieldInterceptor Interceptor = FieldInterceptionHelper.ExtractFieldInterceptor(entity);
return Interceptor.EntityName;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad replace all, fixed locally, not yet pushed. (Fixed in comments/string too.)

.ConnectionReleaseMode()
.FlushMode()
.Interceptor()
.OpenSession();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to do all that with the new method if you want to be as close as possible... But we have no covering tests for that indeed: in the tests, I have just call Connection(), and that is enough for all of them.


/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("never")]
Never,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall be Never = Manual, (as in another place)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semantically cleaner, but not sure the generator from xsd would do that, it has no mean to know it should (or I do not know how to tell it in xsd).

@hazzik
Copy link
Member

hazzik commented May 5, 2017

It feels like some of the methods need to be CSharpified (eg. replaced with properties).

@hazzik
Copy link
Member

hazzik commented May 5, 2017

LGTM

@fredericDelaporte
Copy link
Member Author

It feels like some of the methods need to be CSharpified (eg. replaced with properties).

At first I wanted to do that for ISessionCreationOptions, but that was then conflicting with ISessionBuilder. Types implementing the former implements the later too. I would then have to either do some additional renaming on ISessionBuilder (which uses a property like naming for methods) and then deviate from Hibernate public API (which I would rather avoid), or implement explicitly ISessionCreationOptions or artificially find some different names for its members (less a trouble than for ISessionBuilder, most users are not supposed to ever see the ISessionCreationOptions interface).

So I have just decided that converting them to properties was not really worth the trouble in that case. Written as comment in its implementing class:

// NH note: it is tempting to convert them to properties, but then their names conflict
// with SessionBuilder interface.

I will add that comment on ISessionCreationOptions directly.

About WithOptions(), since it returns a new object at each call, it does not look as a good fit for property semantic.

Would you rather handle ISessionCreationOptions case differently? Since some of its members naming does already look a bit weird, why not additionally rename the others in order to avoid the conflict with ISessionBuilder, if you wish.

Have you seen other missed case of property conversion?

@fredericDelaporte
Copy link
Member Author

(Pushed the fixes I had announced in review.)

@fredericDelaporte fredericDelaporte added this to the 5.0.0 milestone May 5, 2017
@fredericDelaporte
Copy link
Member Author

Found a bug, will fix and add test cases.

@fredericDelaporte
Copy link
Member Author

Bugs fixed (a SetSelf call and a reset of user supplied connection were missing for shared case), test cases added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants